package Control;

import javax.swing.JOptionPane;

import Entity.MsgPackage;
import GUI.DurationStageManager_GUI;
import GUI.ScreenManager;

/**
 * Controls the instance of durationStageManager
 * This class sends and gets data from the server 
 * and display it on the panel.
 * @author Nofar
 *
 */ 
public class DurationStageManager_Control {
	private DurationStageManager_GUI durationSM_GUI;
	private MsgPackage durationSM_MSG; 
	private String[] data;
	
	/**
	 * the constructor
	 */
	public DurationStageManager_Control(){
		durationSM_GUI= new DurationStageManager_GUI();
		durationSM_MSG= new MsgPackage();
		data= new String [2];
	}
	
	/**
	 * 
	 * @return durationSM_GUI
	 */
	public DurationStageManager_GUI getdurationSM_GUI(){
		return durationSM_GUI;
	}
	
	/**
	 * This method sends the stage manager duration in the first and third stages
	 *  to the  server and get an answer (received from query from database) 
	 *  and the control display it in a message
	 */
	public boolean submit_pressed(String string, String stageName){
		data[2]=(String) durationSM_GUI.getNumDay().getSelectedItem();
		if(data.equals("")){
			JOptionPane.showMessageDialog(null, "No option was selected", "ERROR", JOptionPane.ERROR_MESSAGE);
            return false;
		}
		data[0]=string.toString();
		data[1]=stageName;
		durationSM_MSG. setObject(data);
		durationSM_MSG.setOp_code(OP_CODE.SET_DURATION_STAGE_MAMAGER);		
		ScreenManager.getConnection().accept(durationSM_MSG);
		Object o = ScreenManager.getConnection().cclient.getMessage();
		Boolean b= (Boolean) o;
		if(b){
			JOptionPane.showMessageDialog(null, "your duration request was successfully updated ", "", JOptionPane.INFORMATION_MESSAGE);
			return true;				
		}
		return false;		
	}
}
	
	
